package cn.sdc.bugKiller.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.sdc.bugKiller.bean.BugDealBean;
import cn.sdc.bugKiller.service.BugDealService;

public class DealBugServlet extends BasicServlet {
	
	public static String DEALBUG_BEAN = "dealBean";
	public static String METHOD_TODEAL = "todeal";
	public static String METHOD_DEL = "del";
	public static String METHOD_CLOSE = "close";
	
	private static BugDealService service = new BugDealService();
	
	public void exceute(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		setBeanName(DEALBUG_BEAN);
		
		Integer bugId = getParamId(req);
		BugDealBean dealBean = null;
		//bug处理页面准备
		if(METHOD_TODEAL.equals(methodName)){
			dealBean = service.getBugDealBeanByBugId(bugId);
		}
		//删除BUG
		else if(METHOD_DEL.equals(methodName)){
			if(service.deleteBugById(bugId)>0){
				resp.sendRedirect(req.getContextPath()+URI_HOME_SERVLET);
				return;
			}
		}
		//强关BUG
		else if(METHOD_CLOSE.equals(methodName)){
			dealBean = service.getBugDealBeanByBugId(bugId);
			dealBean = service.forceClosedBugProcess(dealBean);
		}
		else{
			dealBean = (BugDealBean) getBean(req,BugDealBean.class);
			dealBean = service.updateBugProcess(dealBean);
		}
		if(dealBean == null || dealBean.getId() == null || dealBean.getBug() == null){
			forward(req, resp, URI_ERROR_JSP);
			return;
		}
		req.setAttribute(DEALBUG_BEAN, dealBean);
		DropdownMaps.setDealBugMap(req);
		forward(req, resp, URI_DEALBUG_JSP);

	}
}
